<?php
/**
 * Hesperos library for Zend Framework
 *
 * This script is protected by copyright. It's use, copying, modification
 * and distribution without written consent of the author is prohibited.
 *
 * @category    Hesperos
 * @package     Acl
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @license     http://www.gnu.org/licenses/lgpl-3.0.txt  GNU Lesser General Public
 * @version     1.0 $Id$
 * @link        http://code.google.com/p/hesperos/
 */

/**
 * Menadżer kontroli dostępu
 *
 * @category    Hesperos
 * @package     Acl
 * @author      Krzysztof Kardasz <krzysztof.kardasz@gmail.com>
 * @copyright   Copyright (c) 2011 Krzysztof Kardasz
 * @version     1.0 $Id$
 */
class Hesperos_Acl_Manager
{
    /**
     * Zend Acl instances
     *
     * @var Zend_Acl []
     */
    static private $_acl = array();

    /**
     * Definiuje instancję
     *
     * @param string $name nazwa
     * @param Zend_Acl $acl obiekt Zend_Acl
     * @return void
     * @throws Hesperos_Exception
     */
    public static function set ($name, Zend_Acl $acl)
    {
        if (isset(self::$_acl[$name])) {
            throw new Hesperos_Exception ('Instance name "' . $name . '" exists');
        }
        self::$_acl[$name] = $acl;
    }

    /**
     * Zwraca flagę czy instancja istnieje
     *
     * @param string $name nazwa
     * @return boolean
     */
    public static function has ($name)
    {
        return isset(self::$_acl[$name]);
    }

    /**
     * Zwraca instancję Zend_Acl
     *
     * @param string $name nazwa
     * @return Zend_Acl
     * @throws Hesperos_Exception
     */
    public static function get ($name)
    {
        if (!isset(self::$_acl[$name])) {
            throw new Hesperos_Exception ('Instance name "' . $name . '" not exists');
        }
        return self::$_acl[$name];
    }
}